import request from '@/utils/request';
import type { ResponseData } from '@/utils/types.d';
import { SUCCESS_CODE } from '@/utils/types.d';
import type { AbnormalAppealTableItem, UpdateAbnormalAppeal } from './types.d';

const moduleBaseUrl = '/api/abnormal-appeal/v1.0.0';

export async function queryAbnormalAppealList(params: any, sort: any) {
  const res = await request<{
    code: number;
    message: string;
    data: { total: number; list: AbnormalAppealTableItem[] };
  }>(`${moduleBaseUrl}/list`, {
    method: 'GET',
    params: {
      data: params,
      sort,
    },
  });
  if (res?.code === SUCCESS_CODE)
    return { success: true, total: res.data.total, data: res.data.list };
  return { success: false, total: 0, data: [] };
}
export async function updateAbnormalAppeal(data4up: UpdateAbnormalAppeal) {
  if (!data4up || Object.keys(data4up).length === 0)
    return { success: false, message: '处理失败，请填入必要信息' };
  const res: ResponseData<null> = await request(`${moduleBaseUrl}/handle`, {
    method: 'PUT',
    data: data4up,
  });
  if (res?.code === SUCCESS_CODE) {
    return { success: true, data: res.data, message: '处理成功' };
  }
  return { success: false, data: res?.data, message: res?.message || '处理失败' };
}
